package com.tianhui.consignortwofei.mvp.ui.activity.hetong.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fgs.common.widget.itemView.DetailItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.hetong.ContractInfo;
import com.tianhui.consignortwofei.mvp.model.hetong.ProductInfo;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.impl.HeTongIOrderStatus;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.IContractType;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class ContractListAdapter extends RecyclerArrayAdapter<ContractInfo> {
    private HeTongIOrderStatus iOrderStatus;

    public ContractListAdapter(Context context, HeTongIOrderStatus iOrderStatus) {
        super(context);
        this.iOrderStatus = iOrderStatus;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderListViewHolder(parent, R.layout.item_contract_list);
    }

    private class OrderListViewHolder extends BaseViewHolder<ContractInfo> {

        private TextView orderNumberTextView;
        private TextView orderStatusTextView;
        private DetailItemView oneDetailItemView;
        private DetailItemView twoDetailItemView;
        private DetailItemView threeDetailItemView;
        private DetailItemView fourDetailItemView;
        private DetailItemView fiveDetailItemView;
        private DetailItemView timeDetailItemView;
        private TextView item_contract_list_downloadTextView;
        private TextView item_contract_list_editTextView;

        private TextView tv_download_pingzheng;

        private DetailItemView div_yifang_name;
        private DetailItemView div_paihao;



        public OrderListViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            orderNumberTextView = getView(R.id.item_contract_list_topLeftTextView);
            orderStatusTextView = getView(R.id.item_contract_list_topRightTextView);

            oneDetailItemView = getView(R.id.item_contract_list_oneDetailItemView);
            twoDetailItemView = getView(R.id.item_contract_list_twoDetailItemView);
            threeDetailItemView = getView(R.id.item_contract_list_threeDetailItemView);
            fourDetailItemView = getView(R.id.item_contract_list_fourDetailItemView);
            fiveDetailItemView = getView(R.id.item_contract_list_fiveDetailItemView);
            timeDetailItemView = getView(R.id.item_contract_list_timeDetailItemView);
            item_contract_list_downloadTextView = getView(R.id.item_contract_list_downloadTextView);
            item_contract_list_editTextView = getView(R.id.item_contract_list_editTextView);

            tv_download_pingzheng = getView(R.id.tv_download_pingzheng);
            div_yifang_name = getView(R.id.div_yifang_name);
            div_paihao = getView(R.id.div_paihao);


            addOnClickListener(R.id.item_contract_list_editTextView);
            addOnClickListener(R.id.item_contract_list_createTextView);
            addOnClickListener(R.id.item_contract_list_downloadTextView);

            addOnClickListener(R.id.item_contract_list_watch);
            addOnClickListener(R.id.item_contract_watch_liucheng);
            addOnClickListener(R.id.tv_download_pingzheng);


        }

        @Override
        public void setData(ContractInfo data) {
            super.setData(data);
            //合同编号
            orderNumberTextView.setText("合同编号：" + data.contractno);
            //合同类型
            oneDetailItemView.setContent(getContractType(data));
            //公司名称
            twoDetailItemView.setContent(data.company_a);
            //制单人
            threeDetailItemView.setContent(data.createName);
            //制单时间
            fourDetailItemView.setContent(data.createTime);
            //签订时间
            timeDetailItemView.setContent(data.signedate);

            //乙方公司
            div_yifang_name.setContent(data.company_b);
            //牌号
            if (null!=data.contractcontentlist&&0<data.contractcontentlist.size()) {
                ProductInfo productInfo = data.contractcontentlist.get(0);
                div_paihao.setContent(productInfo.name+" "+productInfo.type);
            }

            //状态
            if (data.isaudit .equals("1")) {
                orderStatusTextView.setText("已审核");
                item_contract_list_downloadTextView.setVisibility(View.VISIBLE);
                tv_download_pingzheng.setVisibility(View.VISIBLE);
                item_contract_list_editTextView.setVisibility(View.GONE);
            } else if (data.isaudit .equals("3")){
                orderStatusTextView.setText("驳回");
                item_contract_list_downloadTextView.setVisibility(View.GONE);
                tv_download_pingzheng.setVisibility(View.GONE);
                item_contract_list_editTextView.setVisibility(View.VISIBLE);
            }else {
                orderStatusTextView.setText("未审核");
                item_contract_list_downloadTextView.setVisibility(View.GONE);
                tv_download_pingzheng.setVisibility(View.GONE);
                item_contract_list_editTextView.setVisibility(View.GONE);
            }

        }

        private String getContractType(ContractInfo info) {
            if (info != null && !TextUtils.isEmpty(info.contracttype)) {
                if (info.contracttype.equals(IContractType.ADVANCE_PAYMENT)) {
                    return getContext().getResources().getString(R.string.string_contract_type_advance);
                } else if (info.contracttype.equals(IContractType.CASH_DEPOSIT)) {
                    return getContext().getResources().getString(R.string.string_contract_type_cash);
                } else if (info.contracttype.equals(IContractType.NO_CASH_DEPOSIT)) {
                    return getContext().getResources().getString(R.string.string_contract_type_no_cash);
                } else if (info.contracttype.equals(IContractType.FUTURES_DEPOSIT)) {
                    return getContext().getResources().getString(R.string.string_contract_type_futures);
                }else if (info.contracttype.equals(IContractType.ACCOUNTING_PERIOD)) {
                    return getContext().getResources().getString(R.string.string_contract_type_accounting);
                }else if (info.contracttype.equals(IContractType.DIAN_JIA)) {
                    return getContext().getResources().getString(R.string.string_contract_type_dianjia);
                }
            }
            return "合同类型";

        }
    }

}
